#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
int main()
{
    struct timeval tv_total;
    struct timeval tv;
    double usec ;
    int64_t usec1;

    unsigned long a = 1;
    unsigned long b = 2;
    double x = (double)(a-b);
    printf("x=%lf\n", x);

    gettimeofday(&tv_total, NULL);
    while(1) {
        static int kruning_times = 1000*1000;
        if(kruning_times -- <= 0) {
            break;
        }

        gettimeofday(&tv, NULL);
        usec = (double)(tv.tv_sec-tv_total.tv_sec)*1e6 + 
                (double)(tv.tv_usec-tv_total.tv_usec);
    }
    printf("usec=%lf\n", usec);

    gettimeofday(&tv_total, NULL);
    while(1) {
        static int kruning_times = 1000*1000;
        if(kruning_times -- <= 0) {
            break;
        }

        gettimeofday(&tv, NULL);
        usec1 = (int64_t)(tv.tv_sec-tv_total.tv_sec)*(int64_t)1000000 + (int64_t)(tv.tv_usec-tv_total.tv_usec);
    }
    printf("usec1=%lld\n", usec1);

    struct timeval tv1 = {0, 999999};
    struct timeval tv2 = {1, 0};
        usec = (double)(tv2.tv_sec-tv1.tv_sec)*1e6 + 
                (double)(tv2.tv_usec-tv1.tv_usec);
        printf("usec=%lf\n", usec);



    return 0;
}
